import asyncio
import time
import requests


async def counter(until: int = 10) -> None:
    now = time.perf_counter()
    print(f"Started counter at {now}")
    for i in range(0, until):
        last = now
        await asyncio.sleep(0.01)
        now = time.perf_counter()
        print(f'{i}: Was asleep for {now - last}s')


def send_request(url: str) -> int:
    print('Sending Http request')
    response = requests.get(url)
    return response.status_code


async def send_async_request(url: str) ->int:
    return await asyncio.to_thread(send_request, url)


async def main1() -> None:
    status_code = send_request('https://www.google.com')
    print(f'Status code: {status_code}')
    await counter()


async def main2() -> None:
    task = asyncio.create_task(counter())
    status_code = await send_async_request('https://www.google.com')
    print(f'Status code: {status_code}')
    
    await task


async def main() -> None:
    # task = asyncio.create_task(counter())
    # status_code = send_request('https://www.google.com')
    # status_code = await send_async_request('https://www.google.com')
    # print(f'Status code: {status_code}')
    
    # await counter()
    # await task
    status_code, _ = await asyncio.gather(
        send_async_request('https://www.google.com'), counter(),
    )
    print(f'Status code: {status_code}')


asyncio.run(main())
